package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhMicroshop;
import com.ruoyi.edh.service.IEdhMicroshopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-微店Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/microshop")
@Api(description = "易订货-微店")
public class EdhMicroshopController extends BaseController {
    @Autowired
    private IEdhMicroshopService edhMicroshopService;

    /**
     * 查询易订货-微店列表
     */
    @GetMapping("/list")
    @ApiOperation("易订货-微店列表")
    public TableDataInfo list(EdhMicroshop edhMicroshop) {
        startPage();
        List<EdhMicroshop> list = edhMicroshopService.selectEdhMicroshopList(edhMicroshop);
        return getDataTable(list);
    }

    /**
     * 导出易订货-微店列表
     */
    @Log(title = "易订货-微店", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-微店列表")
    public AjaxResult export(EdhMicroshop edhMicroshop) {
        List<EdhMicroshop> list = edhMicroshopService.selectEdhMicroshopList(edhMicroshop);
        ExcelUtil<EdhMicroshop> util = new ExcelUtil<EdhMicroshop>(EdhMicroshop.class);
        return util.exportExcel(list, "microshop");
    }

    /**
     * 根据用户id查询微店详情
     */
    @GetMapping
    @ApiOperation("根据用户id查询微店详情")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long")
    public AjaxResult getInfo(Long userId) {
        return AjaxResult.success(edhMicroshopService.selectEdhMicroshopByUserId(userId));
    }

    /**
     * 根据用户id查询微店详情
     */
    @GetMapping("/h5")
    @ApiOperation("根据用户id查询微店详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "goodsName", value = "商品", required = false, dataType = "String")
    })
    public AjaxResult getInfoh5(Long userId, String goodsName) {
        return AjaxResult.success(edhMicroshopService.selectEdhMicroshopByUserId(userId, goodsName));
    }


    /**
     * 新增易订货-微店
     */
    @Log(title = "易订货-微店", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-微店")
    public AjaxResult add(@RequestBody EdhMicroshop edhMicroshop) {
        return toAjax(edhMicroshopService.insertEdhMicroshop(edhMicroshop));
    }

    /**
     * 修改易订货-微店
     */
    @Log(title = "易订货-微店", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-微店")
    public AjaxResult edit(@RequestBody EdhMicroshop edhMicroshop) {
        return toAjax(edhMicroshopService.updateEdhMicroshop(edhMicroshop));
    }

    /**
     * 删除易订货-微店
     */
    @Log(title = "易订货-微店", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-微店")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhMicroshopService.deleteEdhMicroshopByIds(ids));
    }
}
